package vn.gq.tym.storytemplate;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.MotionEvent;
import android.view.View;
import android.view.Window;
import android.widget.ImageView;

public class SplashActivity extends Activity {

	protected boolean active = true;
	protected int splashTime = 2000;
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		requestWindowFeature(Window.FEATURE_NO_TITLE);
		super.onCreate(savedInstanceState);
		setContentView(R.layout.splash);
		ImageView imv = (ImageView) findViewById(R.id.imageview);
		imv.setOnTouchListener(new View.OnTouchListener() {
			
			@Override
			public boolean onTouch(View v, MotionEvent event) {
				
				if (event.getAction() == MotionEvent.ACTION_DOWN) {
					active = false;
				}
				return true;
			}
		});
		
		Thread splashThread = new Thread() {

			@Override
			public void run() {
				try {
					int waited = 0;
					while (active && (waited < splashTime)) {
						sleep(100);
						if (active) {
							waited += 100;
						}
					}
				} catch(InterruptedException e) {
					
				} finally {
					Intent intent = new Intent(SplashActivity.this, IntroActivity.class);
					startActivity(intent);
					finish();
				}
			}
			
		};
		splashThread.start();
	}

	
}
